<template>
    <div>
        <div class="LoginPassWord">
            <div class="LoginPassWord-Header">
                <h1>密码登录</h1>
            </div>
            <div class="LoginPassWord-Body">
                <form class="LoginPassWord-InputBox">
                    <p class="LoginPassWord-tips"></p>
                    <div class="LoginPassWord-Input Input-User">
                        <input type="text" placeholder="请输入用户名" v-model="user">
                    </div>
                    <div class="LoginPassWord-Input Input-Password">
                        <input type="password" placeholder="请输入密码" autocomplete="" v-model="password">
                    </div>
                    <button class="LoginPhone-buttom" style="color: #fff;" @click.prevent="toUserView">登录</button>
                    <div class="Login-Serve">
                        <van-checkbox v-model="checked">
                            我已阅读并同意
                            <span>《服务协议》</span>
                            和
                            <span>《隐私政策》</span>
                        </van-checkbox>
                    </div>
                </form>
            </div>
        </div>
    </div>
</template>
<script>
import { getUserdata } from '../api/login.js'
export default {
    data() {
        return {
            checked: false,
            user:'',
            password:''
        }
    },
    methods: {
        async toUserView(){
            if(this.checked){
                if(this.user.trim()!="" && this.password.trim()!=""){
                    let data= await getUserdata({
                        username:this.user,
                        password:this.password
                    })
                    data=data.data
                    console.log(data);
                    window.localStorage.setItem('UserData',JSON.stringify({token:data.userInfo.token,UseName:data.userInfo.username,imgUrl:data.userInfo.img_url}))
                    this.$router.back()
                }else{
                    this.$toast.fail({message:'请输入账号和密码', position: 'bottom',})
                }
            }else{
                this.$toast.fail({message:'请阅读并同意《服务协议》和《隐私政策》', position: 'bottom'})
            }
        }
    },
}
</script>
<style lang="scss">
.LoginPassWord {
    .LoginPassWord-Header {
        height: 38px;
        margin: 58px 0;
        text-align: center;
        font-size: 30px;
    }

    .LoginPassWord-Body {
        .LoginPassWord-InputBox {
            display: flex;
            flex-direction: column;

            .LoginPassWord-tips {
                font-size: 12px;
                color: #9c9c9c;
                text-indent: 15px;
            }

            .LoginPassWord-Input {
                display: flex;
                margin-top: 8px;
                padding: 12px 0;
                box-sizing: border-box;
                background-color: #f7f7f7;
                border-radius: 6px;
                margin-bottom: 24px;

                .AreaSelect {
                    padding: 0 12px 0 12px;
                    border-right: 2px solid #e4e4e4;
                    font-size: 14px;

                    i {
                        font-size: 12px;
                        color: #a3a3a3;
                        padding-left: 6px;
                    }
                }

                input {
                    outline: none;
                    border: none;
                    padding-left: 12px;
                    font-size: 14px;
                    background-color: transparent;
                }
            }

            button {
                padding: 15px 0;
                box-sizing: border-box;
                height: 48px;
                display: flex;
                align-items: center;
                justify-content: center;
                border: none;
                background-color: #1367fb;
                border-radius: 10px;
                color: #ffffff4f;
            }

            .Login-Serve {
                margin-top: 16px;
                display: flex;
                justify-content: center;

                .van-checkbox {

                    .van-checkbox__label {
                        font-size: 12px;

                        span {
                            color: #1367fb;
                        }
                    }
                }
            }

        }
    }
}
</style>